// pages/privilege/privilege.js
import {getxitong} from "../../network/requestAll"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    xitongList:[],
    checked:false
  },
  onChange({detail}) {
    console.log(detail);
    let that=this
    if(detail){
      wx.setStorageSync('checked', true)
      this.setData({
        checked: true
      });
      wx.authorize({
        scope: 'scope.userLocation',
        success(){
          that.setData({
            checked: true
          });
        }
      })
    }
  },
  onChange2({detail}) {
    console.log(detail);
    let that=this
    if(detail){
      wx.authorize({
        scope: 'scope.camera',
        success(){
          that.setData({
            checked2: true
          });
        },
        fail(){
          wx.setStorageSync('checked2', false)
          that.setData({
            checked2: false
          });
        }
      })
    }
  },
  onChange3({detail}) {
    console.log(detail);
    let that=this
    if(detail){
      wx.setStorageSync('checked3', true)
      this.setData({
        checked3: true
      });
      wx.authorize({
        scope: 'scope.record',
        success(){
          that.setData({
            checked3: true
          });
        }
      })
    }
  },
  onChange4({detail}) {
    console.log(detail);
    let that=this
    if(detail){
      wx.setStorageSync('checked4', true)
      this.setData({
        checked4: true
      });
      wx.authorize({
        scope: 'scope.addPhoneContact',
        success(){
          that.setData({
            checked4: true
          });
        }
      })

    }
  },
  onChange5({detail}) {
    console.log(detail);
    if(detail){
      wx.setStorageSync('checked5', true)
      wx.authorize({
        scope: 'scope.camera',
        success(){
          that.setData({
            checked5: true
          });
        }
      })
    }
  },
  onLoad(options) {
    this.setData({
      checked: wx.getStorageSync('checked'),
      checked2: wx.getStorageSync('checked2'),
      checked3: wx.getStorageSync('checked3'),
      checked4: wx.getStorageSync('checked4'),
      checked5: wx.getStorageSync('checked5')
    });
    getxitong().then(res=>{
      console.log(res);
      this.setData({
        xitongList:JSON.parse(res.data.data.setList)
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})